//
//  InformationFeedbackViewController.m
//  HJB_project
//
//  Created by jiezsoft.com on 14-12-23.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "InformationFeedbackViewController.h"
#import "UIViewExt.h"
#import "RDVTabBarController.h"
#import "JSONKit.h"
#import "HAODEsingleton.h"
#import "HttpRequest.h"
#import "SelectTheCertificationViewController.h"
@interface InformationFeedbackViewController ()<UITextViewDelegate,UIGestureRecognizerDelegate,UIScrollViewDelegate>

@end

@implementation InformationFeedbackViewController
{UIScrollView*mainScroll;
    UITextView* tv;
    UILabel * label;
    UIImageView*imagess;
    UIButton* Leavemessage;
}
@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
     [[self rdv_tabBarController] setTabBarHidden:YES];
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"Token"];
    if (Token ==nil) {
        Token=@"dd";
    }
    
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"Token"];
    
    
    
    
    
    
    
   
    self.title = @"信息反馈";
   
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [self.view addGestureRecognizer:singleFingerOne];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
      
                                                                     UITextAttributeFont,nil]];

    self.view. backgroundColor=[UIColor colorWithRed:255/255.00 green:255/255.00 blue:255/255.00 alpha:1.0];
    mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
    
    [self.view addSubview:mainScroll];
    [mainScroll setBackgroundColor:[UIColor whiteColor]];
    mainScroll.delegate = self;
    mainScroll.userInteractionEnabled = YES;
    mainScroll.scrollEnabled = YES;
    

    
    tv=[[UITextView alloc]init];
    tv.frame=CGRectMake(15, 20, ScreenWidth-30, 180);
    tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/HJB_project  /HJB_project.xcodeproj
    tv.scrollEnabled = YES;//是否可以拖动
    tv.delegate=self;
//    tv.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高
    tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
    tv.layer.borderWidth =0.3;
    CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 208/255.0, 208/255.0, 208/255.0, 1.0 });
    [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
    tv.layer.cornerRadius =0;
    [mainScroll addSubview:tv];
    
    
    
    imagess=[[UIImageView alloc]initWithFrame:CGRectMake(15, 10, 51/3, 43/3)];
    imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
    [tv addSubview:imagess];
   
  
    
   
    
    UILabel *CardName = [[UILabel alloc]initWithFrame:CGRectMake(15, tv.bottom+30 , ScreenWidth-60, 15)];
    CardName.text = @"请描述下你的问题";
    CardName.textColor=[UIColor blackColor];
    CardName .font = [UIFont systemFontOfSize:15];
    [mainScroll addSubview:CardName];
    UILabel *CardName1 = [[UILabel alloc]initWithFrame:CGRectMake(15, CardName.bottom+10 , 90, 15)];
    CardName1.text = @"客服工作时间";
    CardName1.textColor=[UIColor grayColor];
    CardName1 .font = [UIFont systemFontOfSize:13];
    [mainScroll addSubview:CardName1];
    UILabel *CardName11 = [[UILabel alloc]initWithFrame:CGRectMake(CardName1.right, CardName.bottom+10 , 90, 15)];
    CardName11.text = @"9:00-18:00";
    CardName11.textColor=[UIColor colorWithRed:0.00/255.00 green:91.00/255.00 blue:207.00/255.00 alpha:1.0];
    CardName11 .font = [UIFont systemFontOfSize:13];
    [mainScroll addSubview:CardName11];
    UILabel *CardName12 = [[UILabel alloc]initWithFrame:CGRectMake(CardName11.right-10, CardName.bottom+10 , 140, 15)];
    CardName12.text = @"内反馈我们会尽快回复";
    CardName12.textColor=[UIColor grayColor];
    CardName12 .font = [UIFont systemFontOfSize:13];
    
    [mainScroll addSubview:CardName12];

    
     Leavemessage = [[UIButton alloc] initWithFrame:CGRectMake(10, CardName12.bottom+200/3, ScreenWidth-20, anniuHeigth)];
    [Leavemessage setTitle:@"提交" forState:UIControlStateNormal];
    [Leavemessage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [Leavemessage.layer setCornerRadius:2.0]; //设置矩圆角半径
    [Leavemessage.layer setBorderWidth:0.3];   //边框宽度
    CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
    [Leavemessage.layer setBorderColor:tureBTncolorref];//边框颜色
     Leavemessage.backgroundColor=huisecolor;
//    [Leavemessage addTarget:self action:@selector(Leavemessage:) forControlEvents:UIControlEventTouchUpInside];
   
    [mainScroll addSubview:Leavemessage];

    
}
     
     
-(void)textViewDidChange:(UITextView *)textView
    {
//        self.examineText =  textView.text;
        if (textView.text.length == 0) {
            [imagess removeFromSuperview];
            
            imagess=[[UIImageView alloc]initWithFrame:CGRectMake(15, 10, 51/3, 51/3)];
            imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
            [tv addSubview:imagess];
           
            [Leavemessage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [Leavemessage.layer setCornerRadius:2.0]; //设置矩圆角半径
            [Leavemessage.layer setBorderWidth:0.3];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
            [Leavemessage.layer setBorderColor:tureBTncolorref];//边框颜色
            Leavemessage.backgroundColor=huisecolor;
            
            
        
        }else{
            [imagess removeFromSuperview];
            
            [Leavemessage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            Leavemessage.backgroundColor=luseColor;
            [Leavemessage.layer setCornerRadius:3.0]; //设置矩圆角半径
            [Leavemessage.layer setBorderWidth:0.3];   //边框宽度
            CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
            CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){204.0/255.0,153.0/255.0, 51.0/255.0, 1.0});
            [Leavemessage.layer setBorderColor:tureBTncolorref];//边框颜色
            [Leavemessage addTarget:self action:@selector(Leavemessage:) forControlEvents:UIControlEventTouchUpInside];
            
            
            
        }  
    } 
    



-(void)Leavemessage:(UIButton*)sender{
     [tv resignFirstResponder];
    if ([tv.text length] <1)
    {
        [self showAlertMessage:@"未输入"];
    }else{

    if ([tv.text length] <3)
    {
        [self showAlertMessage:@"字数太少"];
    }else{
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];
        [params setValue:tv.text forKey:@"scontent"];
        
        
     
        
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        [HttpRequest requestData:@"System/Suggestion/Add" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                NSLog(@"33333333====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
               
                    [Global showTextHudSub:requestResultStr view:self.view];
         
                    
                    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
                    

                
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    // [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==8888) {
                        
                        
                        SelectTheCertificationViewController * Login=[[SelectTheCertificationViewController alloc]init];
                        
                        [self.navigationController pushViewController:Login animated:YES];
                        
                    }
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==4444) {
                        [self showAlertMessage:@"账号信息未认证通过，请从新上传"];
                        
                        SelectTheCertificationViewController * Login=[[SelectTheCertificationViewController alloc]init];
                        
                        [self.navigationController pushViewController:Login animated:YES];
                        
                    }
                    

                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
    }
    }
    
}


- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}


- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(void)OnTapDone{
    [tv resignFirstResponder];
    
}

//回收键盘
-(void)closeKeyBoad
{
    [tv resignFirstResponder];
//    [PasswordTextField resignFirstResponder];
    //    [VerificationCode resignFirstResponder];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
